package com.hellobike.haxing.modules.wms.service.impl;

import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.hellobike.haxing.modules.wms.dto.ExportStockBatchLocDto;
import com.hellobike.haxing.modules.wms.dto.StockBatchLocDto;
import com.hellobike.haxing.modules.wms.entity.StockBatchLoc;
import com.hellobike.haxing.modules.wms.mapper.StockBatchLocMapper;
import com.hellobike.haxing.modules.wms.service.IStockBatchLocService;
import org.springframework.stereotype.Service;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;

import java.math.BigDecimal;
import java.util.List;

/**
 * @Description: t_wms_stock_batch_loc
 * @Author: haxing-boot
 * @Date:   2020-01-09
 * @Version: V1.0
 */
@Service
public class StockBatchLocServiceImpl extends ServiceImpl<StockBatchLocMapper, StockBatchLoc> implements IStockBatchLocService {

    @Override
    public StockBatchLoc getBySkuIdAndLocIdAndBatchIdAndWarehouseId(Long skuId, Long locId, Long batchId, Long warehouseId) {
        StockBatchLoc s = new StockBatchLoc();
        s.setSkuId(skuId);
        s.setLocId(locId);
        s.setBatchId(batchId);
        s.setWarehouseId(warehouseId);
        Wrapper<StockBatchLoc> wrapper = new QueryWrapper<>(s);
        return baseMapper.selectOne(wrapper);
    }

    @Override
    public boolean addStock(Long id,BigDecimal addQty) {
        return baseMapper.addStock(id,addQty) == 1;
    }

    @Override
    public List<StockBatchLoc> queryStockBySkuIdAndWarehouseId(Long skuId, Long warehouseId) {
        StockBatchLoc s = new StockBatchLoc();
        s.setSkuId(skuId);
        s.setWarehouseId(warehouseId);
        Wrapper<StockBatchLoc> wrapper = new QueryWrapper<>(s);
        return baseMapper.selectList(wrapper);
    }

    @Override
    public boolean subStock(Long id, BigDecimal qty) {
        return baseMapper.subStock(id,qty) == 1;
    }

    @Override
    public IPage<StockBatchLocDto> pageByStockBatchLocDto(Page<StockBatchLocDto> page, StockBatchLocDto stockBatchLoc) {
        return baseMapper.pageByStockBatchLocDto(page,stockBatchLoc);
    }

    @Override
    public List<ExportStockBatchLocDto> exportStockBatchLoc(StockBatchLocDto stockBatchLoc) {
        return baseMapper.exportStockBatchLoc(stockBatchLoc);
    }
}
